package com.sskj.b70.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.m.HttpConfig;
import com.sskj.b70.m.bean.HttpData;
import com.sskj.b70.m.http.JsonCallBack;
import com.sskj.b70.p.base.BasePresenter;
import com.sskj.b70.utils.ToastUtil;
import com.sskj.b70.v.activity.BindEmailActivity;

/**
 * Created by Administrator on 2018/4/2 0002.
 */

public class BindEmailPresenter extends BasePresenter<BindEmailActivity> {

    public void requestBindEmail(String newEmail, String code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BIND_EMAIL)
                .params("id", MyAppLication.getID())
                .params("code", code)
                .params("email", newEmail)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getStatus() == HttpConfig.STATUS_OK) {
                            ToastUtil.showShort(httpListData.getMsg());
                            mView.onResponseSuccess();
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }
                });
    }

    public void sendEmailCode(String email) {
        httpService.sendEmailCode(email)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.status == HttpConfig.STATUS_OK) {  // 0代表成功
                            mView.sendCodeOk();
                        } else {
                            mView.sendCodeError();
                        }
                    }
                });

    }
}
